<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all"/>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css"
      media="all"/>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<!--<link href="--><?php //echo URL::base() ?><!--media/vendor/fixtable/css/component.css" rel="stylesheet">-->
<!--<link href="--><?php //echo URL::base() ?><!--media/vendor/fixtable/css/normalize.css" rel="stylesheet">-->
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.printPage.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#inventory_time').datetimepicker({
            dateFormat: 'yy-mm-dd',
            timeFormat: 'HH:mm:ss',
            maxDate: new Date(),
        });

//选择临时退款时，需输入借出单号
        $("#type").change(function () {
            if ($("#type").val() != 50) {
                $("#deliveryorders_id").val('ok');
                $("#jiechu").hide(1000);

            } else {
                $("#jiechu").show(1000);
                $("#deliveryorders_id").val('');
            }
        });

        $("#warehouse_quantity").keyup(function () {
            $.post(
                "<?php echo URL::base() ?>warehouse/get_sku_price",
                {sku: $.trim($("input[name='sku']").val()), supplier_id : $("#supplier_id").val()},
                function (data) {
                    data = JSON.parse(data);

                    //$("input[name='single_price']").val(data);
// 					$("#single_price").val(0);

                    cal_cost_money();
                    var type = $("#type").val();
                    if (!(type == 50 || type == 40)) {
                        $("#single_price").val(parseFloat(data).toFixed(4));

                        $('#single_price').trigger('blur');
                    }

                });
        });
//输入单价时，修改金额和成本
        $("#single_price").blur(function () {
            $('#money').val(($(this).val() * $("#warehouse_quantity").val()).toFixed(4));
            $('#cost').val((parseFloat($(this).val() * $("#warehouse_quantity").val()) + parseFloat($("#transportation_expense").val())).toFixed(4));
        });

//输入运费时修改成本
        $("#transportation_expense").blur(function () {
            $('#cost').val((parseFloat($("#cost").val()) + parseFloat($("#transportation_expense").val())).toFixed(4));
        });
        $(".supplierform").Validform({
            tiptype: 2,
            ajaxPost: true,
            callback: function (data) {
                setTimeout(function () {
                    $.Hidemsg(); //公用方法关闭信息提示框;显示方法是$.Showmsg("message goes here.");
                }, 1500);
                if (data.status == 'y') {

                    $('.supplierform')[0].reset();

                    var url = "<?php echo URL::base() ?>inventory/Reportprint/in?id=" + data.id;
                    //$('.btnPrint').show().attr('href',url);
                    $("#jiechu").hide();
                }
            },
        });

        $('select[name=warehouseid]').change(function () {
            var ware_id = $(this).find('option:selected').val();
            $('select[name=enterprise_dominant] option:not([value=0])').remove();
            if(typeof(warehouses[ware_id]) == 'undefined') {
                $('td.warehouse').text('');
                return ;
            }
            var warehouse = warehouses[ware_id];
            if(typeof(warehouse.enterprise_dominant) != 'object') {
                alert('请联系管理员正确配置仓库主体信息');
                return ;
            }
            for(var i in warehouse.enterprise_dominant) {
                var enterprise = warehouse.enterprise_dominant[i];
                $('<option value="'+enterprise.id+'">'+enterprise.name+'</option>').appendTo('select[name=enterprise_dominant]');
            }
        });

        $("input[name='sku']").blur(function () {
            $("#warehouse_quantity").val(0);
            $("#single_price").val(0);
            $("#supplier_id").val(0);
            $("#money").val(0);
            $("#cost").val(0);
            $("#transportation_expense").val(0);

            $.get(
                "<?php echo URL::base() ?>inventory/deliverycheck/load_sku_info",
                {sku: $.trim($(this).val()), warehouseid : $("#warehouseid").val()},
                function (data) {
                    data = JSON.parse(data);
                    if (data.status == 'y') {
                        $("input[name='sku_name']").val(data.info['products_name_cn']);
                        $("input[name='storage_position']").val(data.info['products_place']);
                    } else {
                        $("input[name='sku_name']").val('未找到对应信息');
                        $("input[name='storage_position']").val('未找到对应信息');
                    }
                });
            $("#supplier_id").empty();
            $("#supplier_id").append("<option value=0>--请选择--</option>");
            if ($.trim($(this).val()) != '') {
                $.get(
                    "<?php echo URL::base() ?>warehouse/get_supplier_by_sku",
                    {sku: $.trim($(this).val())},
                    function (data) {
                        data = JSON.parse(data);
                        for (i = 0; i < data.length; i++) {
                            //START------------------------------------------CWY--------------------------------
                            $("#supplier_id").append("<option value='" + data[i]['id'] + "'>" + data[i]['name'] + "</option>");
                            //END------------------------------------------END--------------------------------
                        }
                    });
            }
        });

        /*$("#supplier_id").change(function(){
         $.post(
         "< ?php echo URL::base() ?>warehouse/get_sku_price",
         {sku:$("input[name='sku']").val()},
         function(data){
         data=JSON.parse(data);

         //$("input[name='single_price']").val(data);
         $("#single_price").val(0);
         $("#display_price").val(data);
         cal_cost_money();
         });
         });*/

        function cal_cost_money() {
            var type = $("#type").val();
            if (type == 50) {
                $.get(
                    "<?php echo URL::base() ?>inventory/warehouse/get_do_cost",
                    {do_id: $.trim($("#deliveryorders_id").val()), sku: $.trim($("#sku").val())},
                    function (data) {
                        data = JSON.parse(data);
                        var count = $("#warehouse_quantity").val();
                        $("#sku").val(data.sku);
                        $("#single_price").val(parseFloat(data.single_price).toFixed(4));
                        $("#money").val(parseFloat(data.money / data.num * count).toFixed(4));
                        $("#cost").val(parseFloat(data.cost / data.num * count).toFixed(4));
                    });

            } else if (type == 40) {
                $("#single_price").val(0);
                $("#money").val(0);
                $("#cost").val(0);
            } else {
                count = parseInt($("#warehouse_quantity").val());
                single_price = $("#single_price").val();
                money = count * single_price;
                $("#money").val(money.toFixed(4));
                $("#cost").val(money.toFixed(4));
            }
        }

        //打印
        $(".btnPrint").myprint();
        //上传表格
        $(".upSuppForm").Validform({
            tiptype: 2,
        });

        $("#printsku").click(function () {
            var sku = $.trim($("#sku").val());
            var place = $("#storage_position").val();
            var warehouseid = $('#warehouseid').val();

            if (sku != '' && place != '') {
                var ob = '?sku=' + sku + "&warehouseid=" + warehouseid;
                var url = "<?php echo url::base(true)?>biaoqian/print_sku" + ob;
                window.open(url);
            } else {
                alert('sku和储位不能为空');

            }

        });
    });


</script>

<form class="supplierform" method="post" action="<?php echo URL::base() ?>warehouse/specialadd">
            <table style="width:700px;" class="table">
                <tr>
                    <td width="30">*</td>
                    <td width="120">选择仓库：</td>
                    <td>
                        <select id='warehouseid' name='warehouseid'>
                            <option value="0">--请选择--</option>
                            <?php foreach ($warehouse as $var) { ?>
                                <option value="<?php echo $var['id'] ?>"><?php echo $var['name'] ?></option>
                            <?php } ?>
                        </select>
                    </td>
                    <td width="160"></td>
                </tr>
                <tr>
                    <td width="30">*</td>
                    <td width="120">选择主体：</td>
                    <td>
                        <select id='enterprise_dominant' name='enterprise_dominant'>
                            <option value="0">--请选择--</option>
                            <?php /*foreach ($enterprise_dominants as $id => $name) { */?><!--
                    <option value="<?php /*echo $id */?>"><?php /*echo $name */?></option>
                --><?php /*} */?>
                        </select>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>*</td>
                    <td width="120">选择入库原因：</td>
                    <td><select id='type' name='type' >
                            <?php foreach ($status as $st): if (($st['number']) == 20) continue; ?>
                                <option
                                value="<?php echo $st['number'] ?>"><?php echo $st['value'] ?></option><?php endforeach; ?>
                        </select></td>
                    <td width="160"></td>
                </tr>

                <tr id="jiechu" style="display:none">
                    <td>*</td>
                    <td width="80">输入临时借出的出库单号</td>
                    <td><input type='text' value='ok' name='deliveryorders_id' id="deliveryorders_id" datatype="*"
                               ajaxurl="<?php echo URL::site() ?>inventory/deliverycheck/checkdoid"
                               sucmsg="临时出库单验证通过" errormsg="输入的临时出库单号错误"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>

                <tr>
                    <td>*</td>
                    <td>SKU：</td>
                    <td><input type="text" value="" name="sku" class="inputxt" id="sku"
                               datatype="*"
                               ajaxurl="<?php echo URL::site() ?>inventory/deliverycheck/checksku"
                               sucmsg="SKU验证通过" errormsg="输入的SKU有误"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need">*</td>
                    <td>供应商：</td>
                    <td>
                        <select id="supplier_id" name="supplier_id" datatype="/^[1-9](\d+)?$/"
                                errormsg="请选择供应商">
                            <option value=''>--请选择--</option>
                        </select>
                    </td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td>*</td>
                    <td>SKU名称：</td>
                    <td><input type="text" value="" name="sku_name" class="inputxt"
                               datatype="*" readonly="readonly"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td>*</td>
                    <td>SKU储位：</td>
                    <td><input type="text" value="" name="storage_position" id="storage_position"
                               class="inputxt" datatype="*" readonly="readonly"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td>*</td>
                    <td>数量：</td>
                    <td><input type="text" id="warehouse_quantity"
                               name="warehouse_quantity" class="inputxt" datatype="/^[1-9](\d+)?$/"
                               errormsg="数量只能为正整数"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <!--<tr>
                    <td class="need">*</td>
                    <td> 入库时间：</td>
                    <td><input type="text" name="warehouse_date" class="inputxt" id='inventory_time' datatype="*"
                               readonly="readonly" value="<?php /*echo date('Y-m-d H:i:s') */?>"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>-->
                <tr>
                    <td>*</td>
                    <td>单价：</td>
                    <td><input type="text" id='single_price' name="single_price" value=0 datatype='/^\d+(\.\d+)?$/'
                               errormsg="单价只能为数字"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>

                <tr>
                    <td class="need">*</td>
                    <td>金额：</td>
                    <td><input type="text" id='money' name="money" value=0 datatype='/^\d+(\.\d+)?$/' errormsg="金额只能为数字"
                               readonly="readonly"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need">*</td>
                    <td>成本：</td>
                    <td><input type="text" id='cost' name="cost" value=0 datatype='/^\d+(\.\d+)?$/' errormsg="成本只能为数字"
                               readonly="readonly"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need">*</td>
                    <td>运费：</td>
                    <td><input type="text" id='transportation_expense'
                               name="transportation_expense" class="inputxt"
                               datatype="/^(\d+)(\.\d+)?$/" value=0 errormsg="运费只能为数字"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need">*</td>
                    <td>备注：</td>
                    <td><input type="text" value="" name="remark" datatype="/[^[\s*]]*$/" id="remark" errormsg="备注不能为空"
                               class="inputxt"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need"></td>
                    <td><input type='button' value='打印标签' id='printsku' class='btn'></td>
                    <td colspan="2">

                        <input type="submit" value="提 交" class='btn btn-info''/>
                        <input type="reset" value="重 置" class='btn'/>
                    </td>
                </tr>
            </table>
        </form>

<a class="btnPrint btn  btn-danger" style="display:none ">打印</a>

<?php
echo '<script>var warehouses = ' . json_encode($warehouse) . ';</script>';
?>
<!--yuqing -->
<!--<div class="">
    <div class="">
        <h2>还料入库上传数据（<lable style="color: #ff0000">仅限还料操作</lable>）：<lable style="color: #ff0000">库存盘点请到 库存查询--><!--盘点库存（新）--><!--</lable></h2>
        <form class="upSuppForm" method='post' action='< ?php /*/*echo URL::site() */*/?>inventory/warehouse/upload_warehouse'
              enctype="multipart/form-data">
            <table class="table">
                <tr>
                    <td class="need"></td>
                    <td>批量上传</td>
                    <td><input type='file' style="line-height: 0px;" name='xls' class="inputxt" datatype="/.+\.xls/"
                               nullmsg="请选择上传文件" errormsg="文件格式只能为xls"/></td>
                    <td>
                        <div class="Validform_checktip"></div>
                    </td>
                </tr>
                <tr>
                    <td class="need"></td>
                    <td></td>
                    <td colspan="2">
                    </td>
                </tr>
            </table>
            <input type='submit' value='上传' class='btn btn-success'/>
            <div class="btn btn-success"><a href="< ?php /*/*echo URL::site() */*/?>inventory/warehouse/down_template"
                                            style="color: #ffffff">下载模版</a></div>
        </form>

    </div>
</div>-->
<!--yuqing -->


